#ifndef __XT_RULEID_H__
#define __XT_RULEID_H__
#include <linux/types.h>

#ifndef RULEID_ELF_HASH
#define RULEID_ELF_HASH
#endif

#ifndef DEBUG_XT_RULEID
#define DEBUG_XT_RULEID
#endif

#define RULEID_HASH_SHIFT	10
#define RULEID_HASH_SIZE	( 1 << RULEID_HASH_SHIFT )
#define RULEID_HASH_MASK	( RULEID_HASH_SIZE - 1 )
#define RULEID_NAME_SIZE	64

#define PROC_PATH "/proc/sys/leadsec"

#ifdef __KERNEL__
//#warning "__KERNEL__ macro enable!!!!"
#endif

#define RULEID_BASE_CTL		1024
enum ruleid_so_get_e {
	RULEID_SO_GET_CNT = RULEID_BASE_CTL,
	RULEID_SO_GET_MAX,
};

enum ruleid_so_set_e {
	RULEID_SO_SET_CNT = RULEID_BASE_CTL,
	RULEID_SO_SET_ENA,
	RULEID_SO_SET_DIS,
	RULEID_SO_FLUSH_CNT,
	RULEID_SO_SET_MAX,
};

/* match struct */
typedef struct xt_ruleid_info {
	char ruleid[RULEID_NAME_SIZE];
	u_int8_t invflags;

}ruleid_match_t;

/* statistics information */
typedef struct ruleid_info {
	char ruleid[RULEID_NAME_SIZE];
	u_int64_t bcnt, pcnt, scnt;
#ifdef __KERNEL__
	struct hlist_node hnode; 
	struct rcu_head rcu;
	atomic_t refcnt;
	spinlock_t lock;
	size_t size;
#else
	u_int8_t pad[20];	/* padding for sizeof!!!! */
#endif	/* __KERNEL__ */

} ruleid_info_t;

#ifdef __KERNEL__
typedef struct ruleid_cfg {
	/* Function of switch */
	u8 ruleid_switch;
	
	/* Maximum limit */
	u32 ruleid_info_max;
	atomic_t ruleid_info_amount;
	
	/* Memory information statistics */
	char memory_info[1024];
	size_t total_alloc_size;
       	size_t total_alloc_realsize;
       	size_t getpages_size;
       	size_t getpages_realsize;
       	u32 getpages_number;
	size_t mem_max_size;
	
} ruleid_cfg_t;

static inline unsigned int
kmalloc_size( size_t size )
{
        unsigned int s;
#define CACHE( x ) if ( size <= x ) { s = x; goto found;}
#include <linux/kmalloc_sizes.h>
        return 0;
found:
        return s;
}

static inline unsigned int
getpages_size( size_t size )
{
        return size == 0 ? 0 : ( PAGE_SIZE << get_order(size) );
}
#endif	/* __KERNEL__ */

#endif	/* __XT_RULEID_H__ */

